define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'shop/finance/index',
                    add_url: 'shop/finance/add',
                    edit_url: 'shop/finance/edit',
                    del_url: 'shop/finance/del',
                    multi_url: 'shop/finance/multi',
                    table: 'finance',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'fina_id',
                sortName: 'fina_id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'fina_id', title: __('Fina_id')},
                        {field: 'fina_type', title: __('Fina_type'), searchList: {"out":__('Out'),"in":__('In'),"recharge":__('Recharge'),"cash":__('Putforward')}, formatter: Table.api.formatter.normal},
                        {field: 'obj_type', title: __('Obj_type')},
                        {field: 'obj_id', title: __('Obj_id')},
                        {field: 'uid', title: __('Uid')},
                        {field: 'username', title: __('Username')},
                        {field: 'desc', title: __('Desc')},
                        {field: 'order_id', title: __('Order_id')},
                        {field: 'fina_cash', title: __('Fina_cash'), operate:'BETWEEN'},
                        {field: 'fina_channel', title: __('Fina_channel'), searchList: {"1":__('Balance'),"2":__('Weixin'),"3":__('Weixin')+__('Balance')}, formatter:function(value,row,index){
                                var keys = typeof this.searchList === 'object' ? Object.keys(this.searchList) : [];
                                var index = keys.indexOf(value.toString());
                                value = value === null ? '' : value.toString();
                                var display = index > -1 ? this.searchList[value] : null;
                                var icon = typeof this.icon !== 'undefined' ? this.icon : null;
                                if (!display) {
                                    display = __(value.charAt(0).toUpperCase() + value.slice(1));
                                }
                                var html = '<span class="text">' + (icon ? '<i class="' + icon + '"></i> ' : '') + display + '</span>';

                                return html;
                            }},
                        {field: 'balance', title: __('Balance'), operate:'BETWEEN'},
                        {field: 'source', title: __('Source'), searchList: {"paike":__('Paike'),"shop":__('Shop'),"system":__('System')}, formatter: Table.api.formatter.normal},
                        {field: 'remark', title: __('Remark')},
                        {field: 'on_time', title: __('On_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });



            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});